﻿namespace PortableRiotGames.Infrastructure.Converters
{
    using Newtonsoft.Json;
    using System;

    public class JsonGameModeConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            throw new NotImplementedException();
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.Value.ToString() == "CLASSIC") return GameMode.Classic;
            if (reader.Value.ToString() == "ODIN") return GameMode.Odin;
            if (reader.Value.ToString() == "ARAM") return GameMode.Aram;
            if (reader.Value.ToString() == "TUTORIAL") return GameMode.Tutorial;
            return GameMode.Classic;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            serializer.Serialize(writer, value.ToNullableString().ToUpper());
        }
    }
}
